package com.example.a22310.myapplication.Model;


import com.example.a22310.myapplication.Beans.Choiceness;
import com.example.a22310.myapplication.Beans.user;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Service.service;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static android.provider.ContactsContract.CommonDataKinds.Website.URL;

public class ActivityModel  {
    private Retrofit retrofit;
    public ActivityModel()
    {

        retrofit= new Retrofit.Builder()
                .baseUrl(URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void activityList(final ActivityLisenter<Choiceness> lisenter) {  //活动部列表
        service service = retrofit.create(service.class);
        Call<Choiceness> call = service.activitylist();
        Callback<Choiceness> callback = new Callback<Choiceness>() {
            @Override
            public void onResponse(Call<Choiceness> call, Response<Choiceness> response) {
                Choiceness activitys = response.body();
                lisenter.onSuccess(activitys);
            }
            @Override

            public void onFailure(Call<Choiceness> call, Throwable t) {
                lisenter.onFailure();
            }
        };
        call.enqueue(callback);
    }


    public void activityAplay(final ActivityLisenter<user> lisenter, int user_id, int activity_id, String activity_name,
                              String activity_type, String activity_price, String user_phone, String name, String paynum) {  //活动部列表
        service service = retrofit.create(service.class);
        Call<user> call = service.activityApply(user_id,activity_id,activity_name,activity_type,
                activity_price,user_phone,name,paynum);
        Callback<user> callback = new Callback<user>() {
            @Override
            public void onResponse(Call<user> call, Response<user> response) {
               user user = response.body();
                lisenter.onSuccess(user);
            }

            @Override
            public void onFailure(Call<user> call, Throwable t) {
                lisenter.onFailure();
            }
        };
        call.enqueue(callback);
    }


    public void trainApplys(final ActivityLisenter<user> lisenter,int userid,int trainid,String name,
                            String price,String phone) {  //活动报名
        service service = retrofit.create(service.class);
        Call<user> call = service.trainApply(userid,trainid,price,name,
                phone);
        Callback<user> callback = new Callback<user>() {
            @Override
            public void onResponse(Call<user> call, Response<user> response) {
                user user = response.body();
                lisenter.onSuccess(user);
            }

            @Override
            public void onFailure(Call<user> call, Throwable t) {
                lisenter.onFailure();
            }


        };
        call.enqueue(callback);
    }



}
